package padrao;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;

import br.com.util.Escritor;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.mapper.MapperWrapper;

public class Main {
	public void execute() {
		try {
			Process p = Runtime.getRuntime().exec("cmd /c dir");
			p.waitFor();
			BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream()));
			String line=reader.readLine();
			while(line != null) {
				System.out.println(line);
				line=reader.readLine();
			}
		} catch(IOException e1) {

		} catch(InterruptedException e2) {

		} 

		System.out.println("Done"); 
	}

	public static void main(String[] args) {
		XStream xstream = new XStream() {
			protected MapperWrapper wrapMapper(MapperWrapper next) {  
				return new MapperWrapper(next) {  
					public boolean shouldSerializeMember(Class definedIn, String fieldName) {  
						return definedIn != Object.class ? super.shouldSerializeMember(definedIn, fieldName) : false;  
					}  
				};  
			}  

		};
		
		LdmlBean l1 = new LdmlBean();
		TagBean t1 = new TagBean("Tag 1");
		l1.setT1(t1);
		
		Escritor e = new Escritor();
		e.abreArquivo("./exemplo.xml", true);
		
		e.gravaArquivo(new String[] { xstream.toXML(l1) } );
		
		e.fechaArquivo();
				
		LdmlBean m = (LdmlBean) xstream.fromXML(new File("./exemplo.xml"));

		System.out.println(m.getT1().getNome());
	}
}
